package main

import (
	"doctor-srv/basic/config"
	"doctor-srv/basic/inits"
	pb "doctor-srv/basic/proto"
	"doctor-srv/handler/service"
	"fmt"
	"log"
	"net"

	"google.golang.org/grpc"
)

func main() {
	// 初始化配置
	inits.InitConfig()
	inits.InitMySQL()

	// 创建gRPC服务器
	grpcServer := grpc.NewServer()

	// 注册所有服务
	pb.RegisterDoctorServer(grpcServer, &service.DoctorService{})
	pb.RegisterPatientServer(grpcServer, &service.PatientService{})
	pb.RegisterConsultationServer(grpcServer, &service.ConsultationService{})
	pb.RegisterMedicineServer(grpcServer, &service.MedicineService{})
	pb.RegisterMedicalRecordServer(grpcServer, &service.MedicalRecordService{})
	pb.RegisterAttachmentServer(grpcServer, &service.AttachmentService{})
	pb.RegisterStatisticsServer(grpcServer, &service.StatisticsService{})

	// 监听端口
	port := config.Conf.Grpc.Port
	lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
	if err != nil {
		log.Fatalf("Failed to listen: %v", err)
	}

	log.Printf("Doctor Service is running on port %d...", port)
	if err := grpcServer.Serve(lis); err != nil {
		log.Fatalf("Failed to serve: %v", err)
	}
}

